<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/inc/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>台账</title>
<%@include file="/inc/head.jsp"%>
<script type="text/javascript">
	var grid;
	$(function() {
		
		$("#hs").dialog('close');
		$("#dlg").dialog('close');
		$("#dlg1").dialog('close');
		$("#dlg2").dialog('close');
		$("#hs").dialog('close');
		grid = $('#grid')
				.datagrid(
						{ //定位到Table标签，Table标签的ID是grid
							url : '${ctx}/base/price/list', //指向后台的Action来获取当前菜单的信息的Json格式的数据
							striped : true,
							collapsible : true,
							pagination : true,
							pageSize : 50,
							pageList : [ 10, 20, 30, 40, 50, 100, 200, 400,
									600, 800, 1000, 1200 ],
							onBeforeLoad : function(param) {
								parent.$.messager.progress({
									text : '数据加载中....'
								});
							},
							onLoadSuccess : function(data) {
								parent.$.messager.progress('close');
							},
							idField : 'id',
							sortName : 'createTime',
							sortOrder : 'desc',
							rownumbers : true,
							queryParams : {
							 
							}, //异步查询的参数
							columns : [ [{
								field : 'ck',
								width : 50,
								checkbox : true
							}, {
								title : 'id',
								width : 100,
								field : 'id',
								editor : {
									type : 'validatebox',
									options : {
										required : true
									}
								},
								hidden : true
							},
									{
										title : '物资名称',
										width : 300,
										field : 'wzmc',
										editor : {
											type : 'validatebox',
											options : {
												required : true
											}
										}
									},
									{
										title : '规格型号',
										width : 150,
										editor : {
											type : 'validatebox',
											options : {
												required : true
											}
										},
										field : 'ggxh'
									},
									{
										title : '类型',
										width : 80,
										editor : {
											type : 'validatebox',
											options : {
												required : true
											}
										},
										field : 'type'
									},
									{
										title : '山前价格',
										width : 80,
										editor : {
											type : 'validatebox',
											options : {
												required : true
											}
										},
										field : 'sqprice'
									},
									{
										title : '台盆价格',
										width : 80,
										editor : {
											type : 'validatebox',
											options : {
												required : true
											}
										},
										field : 'tfprice'
									},
									{
										title : '状态',
										width : 80,
										editor : {
											type : 'validatebox',
											options : {
												required : true
											}
										},
										field : 'zt'
									},
									{
										title : '计量单位',
										width : 80,
										editor : {
											type : 'validatebox',
											options : {
												required : true
											}
										},
										field : 'jldw'
									},
									{
										title : '单位',
										width : 80,
										editor : {
											type : 'validatebox',
											options : {
												required : true
											}
										},
										field : 'pid',
										formatter : function(value, obj) {
											var $value = "";
											if (value == "1" ) {
												$value = "井控中心";
											} else if(value == "2" ){
												$value = "钻具中心";
											}
											else if(value == "3" ){
												$value = "工具中心";
											}
											else{
												$value = "";
											}
											return $value;
										} 
									},
									{
										title : '权重',
										width : 80,
										editor : {
											type : 'validatebox',
											options : {
												required : true
											}
										},
										field : 'weight'
									},
									{
										title : '备注',
										width : 150,
										editor : {
											type : 'validatebox',
											options : {
												required : true
											}
										},
										field : 'remark'
									},{
										field: 'operate',
										title : '操作',
										width : 140,
										formatter: function(value, rowData, rowIndex){
								                return '<a href="javascript:void(0)"  onclick="update(' + rowIndex + ')">修改</a>';
								            }
									}] ],
							toolbar : '#toolbar'
						});

		
	});
	
	//编辑操作
	 function update(index) {
		 var row = $("#grid").datagrid('getRows')[index];
			$("#ggxh1").val(row.ggxh);
			$("#wzmc1").val(row.wzmc);
			$("#id").val(row.id);
			
			$("#type1").val(row.type);
			$("#sqprice1").val(row.sqprice);
			$("#tfprice1").val(row.tfprice);
			$("#jldw1").val(row.jldw);
			
			$("#weight1").val(row.weight);
			$("#remark1").val(row.remark);
			
			var zt = document.getElementById("zt1");
			for (var i = 0; i < zt.length; i++) {//给select赋值 
				if (row.zt == zt.options[i].value) {
					zt.options[i].selected = true;
				}
			}
			
			var zt = document.getElementById("pid1");
			for (var i = 0; i < zt.length; i++) {//给select赋值 
				if (row.zt == zt.options[i].value) {
					zt.options[i].selected = true;
				}
			}
			$('#dlg2').dialog('open');
	} 
	
	function ShowAddDialog() {
		$('#dlg').dialog('open');
	}

	//删除
	function deleteMessage(){
	var row = $("#grid").datagrid('getSelections');
	if (row.length > 0) {
	$.messager.confirm("提示","你确定要删除吗?",function(r) {
						if (r) {
							if (r) {
								var ids = "";
								for ( var i = 0; i < row.length; i++) {
									ids += row[i].id+ ",";
								}
						$.ajax({
								url : '${ctx}/base/price/deleteByIds',
								type : 'post',
								dataType : 'json',
								data : {
									ids : ids
								},
								success : function(data) {
									if (data.result) { // 删除成功
									window.location.href = "${ctx}/base/price/view";
									} else { // 删除失败
									$.messager.alert('系统提示', '删除失败！', 'info');
									}
									}
								});
							}
						}
					});
				}
	}
	//导出
	function exployOut(){
		$.messager.confirm("提示","你确定要导出吗?",function(r) {
			if (r) {
				if (r) {
					window.location.href = "${ctx}/base/price/exceloutput?"+$("#sear").serialize();
				}
			}
		});
	}
	
	//清楚查询条件
    function ClearQuery() {
        $("#tblQuery").find("input").val("");
    }
</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
	<div id="toolbar" style="display: none;">
		<div style="padding: 0 0 0 7px; color: #333;">
			<form id="sear"  method="post">
				<table width="100%" id="tblQuery">
					<tr>
						<td>物资名称：</td>
						<td><input type="text" style="width: 120px"
							name="search.wzmc_like" id="wzmc"></td>
						<td>规格型号：</td>
						<td><input type="text" style="width: 120px"
							name="search.ggxh_eq" id="ggxh"></td>
					</tr>
					
						<tr>
						<td>类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;型：</td>
						<td><input type="text" style="width: 120px"
							name="search.type_like" id="type"></td>
						<td>计量单位：</td>
						<td><input type="text" style="width: 120px"
							name="search.jldw_eq" id="jldw"></td>
						<td><input type="button" data-options="iconCls:'icon-search'" value="查询" onclick="grid.datagrid('load',sy.serializeObject($('#sear')));"></td>
					</tr>
				</table>

			</form>
		</div>
		<hr style="border: solid 1px grap; width: 100%">
		<div>
			<a href="#" class="easyui-linkbutton"
				data-options="iconCls:'icon-add'" onclick="ShowAddDialog();" >添加</a><a class="easyui-linkbutton"
				data-options="iconCls:'icon-remove'" href="javascript:void(0)" onclick="deleteMessage();">批量删除</a>
		</div>
	</div>

	<%--grid model --%>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid" data-options="fit:true,border:false"></table>
	</div>
	<%--end grid model --%>

	<!-- 为修改数据赋值 -->
	<input type="hidden" value="${parm.serialNumber }" id="parm">
	<input type="hidden" value="${parm.teamName }" id="teamName">
	<input type="hidden" value="${parm.manufacturer }" id="manufacturer">
	<input type="hidden" value="${parm.startCastTime }" id="startCastTime">
	<input type="hidden" value="${parm.endCastTime }" id="endCastTime">
	<input type="hidden" value="${parm.retestingPeriod }"
		id="retestingPeriod">
	<input type="hidden" value="${parm.type }" id="type">
	<input type="hidden" value="${parm.currentState }" id="currentState">
	<input type="hidden" value="${parm.startCheckAndRepairDate }"
		id="startCheckAndRepairDate">
	<input type="hidden" value="${parm.endCheckAndRepairDate }"
		id="endCheckAndRepairDate">

	<%--添加 dialog --%>
	<div id="dlg" class="easyui-dialog" title="添加项目部信息"
		style="width: 600px; height: 450px; padding: 10px;"
		data-options="buttons: [{
		text:'保存',
		iconCls:'icon-ok',
		handler:function(){
		$.ajax({
			cache : true,
			type : 'post',
			url:'${ctx}/base/price/addMessage',
			data : $('#commentForm').serialize(),
			dataType:'json',
			async : false,
			error: function(data) {
                 $.messager.alert('系统提示', data.msg, 'info');
                },
            success: function(data) {
                 if(data.msg){
                  $('#dlg').dialog('close');
                  window.location.href = '${ctx}/base/price/view';
                 }
            	 console.info(data.msg);
                 $.messager.alert('系统提示', data.msg, 'info');
                }
		});
		}
		},{
		text:'取消',
		handler:function(){
		$(dlg).dialog('close');}}]">

		<form class="easyui-form" id="commentForm" method="post" >
			<table style="border-collapse:separate; border-spacing:10px;">
			<tr>
			<td><label>物资名称：</label>
			<input type="text" name="wzmc" value="" class="required" title="不能为空!" style="width: 137px; height: 22px;"/> &nbsp;<font color=red>*</font> </td>
			<td><label>型号：</label>
			<input type="text" name="ggxh" value="" class="required" title="不能为空!" style="width: 137px; height: 22px;"/> &nbsp;<font color=red>*</font></td>
			</tr>
			
			<tr>
			<td><label>台盆价格：</label>
			<input type="text" name="tfprice" value="" class="required" title="不能为空!" style="width: 137px; height: 22px;"/> &nbsp;<font color=red>*</font></td>
			
			<td><label>状态：</label>
			<select class="easyui-combobox " name="zt"
				id="zt" style="width: 140px; height: 28px;">
				<option value="修井" selected="selected">修井</option>
				<option value="钻井" selected="selected">钻井</option>
			</select>
			</td>
			</tr>
			<tr>
			<td><label>山前价格：</label>
			<input type="text" name="sqprice" value="" class="required" title="不能为空!" style="width: 137px; height: 22px;"/> &nbsp;<font color=red>*</font> </td>
			<td><label>类型：</label>
			<input type="text" name="type" value="" class="required" title="不能为空!" style="width: 137px; height: 22px;"/> &nbsp;<font color=red>*</font></td>
			</tr>
			
			<tr>
			<td><label>计量单位：</label>
			<input type="text" name="jldw" value="" class="required" title="不能为空!" style="width: 137px; height: 22px;"/> &nbsp;<font color=red>*</font></td>
			<td><label>权重：</label>
			<input type="text" name="weight" value="1" class="required" title="不能为空!" style="width: 137px; height: 22px;"/> &nbsp;<font color=red>*</font></td>
			</tr>
			<tr>
			<td><label>单位类别：</label>
			<select class="easyui-combobox " name="pid"
				id="zt" style="width: 140px; height: 28px;">
				<option value="1" selected="selected">井控中心</option>
				<option value="2" selected="selected">钻具中心</option>
				<option value="3" selected="selected">工具中心</option>
			</select>
			</td>
			</tr>
			<tr><td colspan="2"><label>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</label> 
			<textarea id="remark" rows=5 cols="45" name="remark" class="textarea easyui-validatebox" ></textarea>  </td>
			</tr>
				</table>
		</form>
	</div>
	
	
	<%--修改 dialog --%>
	<div id="dlg2" class="easyui-dialog" title="修改项目部信息"
		style="width: 600px; height: 350px; padding: 10px;"
		data-options="buttons: [{
		text:'修改',
		iconCls:'icon-ok',
		handler:function(){
		$.ajax({
			cache : true,
			type : 'post',
			url:'${ctx}/base/price/editMessage',
			data : $('#editForm').serialize(),
			dataType:'json',
			async : false,
			error: function(data) {
                 $.messager.alert('系统提示', data.msg, 'info');
                },
            success: function(data) {
                 if(data.msg){
                  $('#dlg2').dialog('close');
                  window.location.href = '${ctx}/base/price/view';
                 }
            	 console.info(data.msg);
                 $.messager.alert('系统提示', data.msg, 'info');
                }
		});
		}
		},{
		text:'取消',
		handler:function(){
		$(dlg2).dialog('close');}}]">

		<form class="easyui-form" id="editForm" method="post" >
			<table style="border-collapse:separate; border-spacing:10px;">
			<tr>
			<td><label>物资名称：</label><input type="hidden" name="id" id="id">
			<input type="text" name="wzmc" id="wzmc1" value="" class="required" title="不能为空!" style="width: 137px; height: 22px;"/> &nbsp;<font color=red>*</font> </td>
			<td><label>型号：</label>
			<input type="text" name="ggxh" value="" id="ggxh1" class="required" title="不能为空!" style="width: 137px; height: 22px;"/> &nbsp;<font color=red>*</font></td>
			</tr>
			
			<tr>
			<td><label>台盆价格：</label>
			<input type="text" name="tfprice" value="" id="tfprice1" class="required" title="不能为空!" style="width: 137px; height: 22px;"/> &nbsp;<font color=red>*</font></td>
			
			<td><label>状态：</label>
			<select  name="zt" 
				id="zt1" style="width: 140px; height: 28px;">
				<option value="修井" selected="selected">修井</option>
				<option value="钻井" selected="selected">钻井</option>
			</select>
			</td>
			</tr>
			<tr>
			<td><label>山前价格：</label>
			<input type="text" name="sqprice" id="sqprice1" value="" class="required" title="不能为空!" style="width: 137px; height: 22px;"/> &nbsp;<font color=red>*</font> </td>
			<td><label>类型：</label>
			<input type="text" name="type" id="type1" value="" class="required" title="不能为空!" style="width: 137px; height: 22px;"/> &nbsp;<font color=red>*</font></td>
			</tr>
			
			<tr>
			<td><label>计量单位：</label>
			<input type="text" name="jldw" id="jldw1" value="" class="required" title="不能为空!" style="width: 137px; height: 22px;"/> &nbsp;<font color=red>*</font></td>
			<td><label>权重：</label>
			<input type="text" name="weight" id="weight1" value="1" class="required" title="不能为空!" style="width: 137px; height: 22px;"/> &nbsp;<font color=red>*</font></td>
			</tr>
			<tr>
			<td><label>单位类别：</label>
			<select  name="pid"
				id="pid1" style="width: 140px; height: 28px;">
				<option value="1" selected="selected">井控中心</option>
				<option value="2" selected="selected">钻具中心</option>
				<option value="3" selected="selected">工具中心</option>
			</select>
			</td>
			</tr>
			<tr><td colspan="2"><label>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</label> 
			<textarea id="remark1" rows=5 cols="45" name="remark" class="textarea easyui-validatebox" ></textarea>  </td>
			</tr>
				</table>
		</form>
	</div>
</body>
</html>
